package com.jiangyg.devtools.ui.table.cell;

import com.intellij.openapi.project.Project;
import org.apache.commons.lang.BooleanUtils;

import javax.swing.*;
import java.awt.*;

/**
 * 类描述：
 *
 * @author jiangyg
 * @version 1.0
 * @date 2023年08月28日
 */
public class CheckBoxCellEditor extends AbstractTableCellEditor {

    private final CheckBoxCellComponent component = new CheckBoxCellComponent();

    public CheckBoxCellEditor(Project project) {
        super(project);
    }

    @Override
    public Component getTableCellEditorComponent(JTable table,
                                                 Object value,
                                                 boolean isSelected,
                                                 int rowIndex,
                                                 int columnIndex) {
        final boolean selected = BooleanUtils.toBoolean(String.valueOf(value));
        component.setSelected(selected);
        return component;
    }

    @Override
    public Object getCellEditorValue() {
        return component.isSelected();
    }

}
